﻿
Imports std

Namespace internalFunctions
    Public Class create_eventComb
        Inherits internalFunction

        Public Class parameters
            Public Const ibase As String = "i"
        End Class

        Private Shared ReadOnly m As iParametersMapping = Nothing

        Shared Sub New()
            initialSerialMapping(m, parameters.ibase)
        End Sub

        Public Sub New()
            MyBase.New("create_eventComb", m, Nothing)
        End Sub

        Private Shared Function callback(ByVal name As String,
                                         ByVal value As String,
                                         ByRef rtn As vector(Of String)) As Boolean
            assert(Not rtn Is Nothing)
            Return rtn.push_back(value)
        End Function

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim vs As vector(Of String) = Nothing
            vs = New vector(Of String)()
            If Not ctx.findVariables(AddressOf callback, string_finder(), parameters.ibase, 0, vs) Then
                ctx.findVariables(AddressOf callback, string_finder(), parameters.ibase, 1, vs)
            End If

            Dim calls As vector(Of _do(Of Boolean)) = Nothing
            calls = New vector(Of _do(Of Boolean))()
            calls.size() = vs.size()
            For i As Int64 = 0 To vs.size() - 1
                If Not function_name_to_call(ctx, vs(i), calls(i)) Then
                    Return False
                End If
            Next

            output = New bare_variable(typeDefination.var, New eventComb(+calls))
            Return True
        End Function

        Private Shared Function function_name_to_call(ByVal ctx As context,
                                                      ByVal i As String,
                                                      ByRef d As _do(Of Boolean)) As Boolean
            assert(Not ctx Is Nothing)
            If isemptystring(i) Then
                Return False
            Else

            End If
        End Function
    End Class
End Namespace
